﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <!-- jsp文件头和头部 -->
    <%@ include file="../admin/top.jsp" %>
</head>
<body>
<div class="container-fluid" id="main-container">

    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <form action="channel/list" method="post" name="userForm" id="userForm">
                    <input type="hidden" name="menuId" value="${page.menuId}">
                    <span style="font-weight: bold; width: 500px; font-size: 18px">渠道商列表(${deviceTotalTime} 更新)</span>
                    <table style="width: 450px">
                        <tr>
                            <td>
						<span class="input-icon">
							<input style="margin-top: 0px;" autocomplete="off" id="nav-search-input" type="text"
                                   name="searchValue" value="${page.searchValue}" placeholder="渠道名称"/>
						</span>
                            </td>
                            <td style="vertical-align:top;">
                                <select class="chzn-select" name="status" data-values="${status}"
                                        data-placeholder="请选择状态" style="vertical-align:top;width: 120px;">
                                    <option value="">状态</option>
                                    <option value="1"
                                            <c:if test="${status == 1}">selected</c:if> >启用
                                    </option>
                                    <option value="0"
                                            <c:if test="${status == 0}">selected</c:if> >禁用
                                    </option>
                                </select>
                            </td>
                            <td style="vertical-align:top;">
                                <button class="btn btn-mini btn-light" onclick="search();" title="检索">
                                    <i id="nav-search-icon" class="icon-search"></i>
                                </button>
                            </td>
                            <td style="vertical-align:top;">
                                <c:if test="${fn:contains(butSet, 'add')}">
                                    <a class="btn btn-small btn-success" onclick="add();">新增</a>
                                </c:if>
                            </td>
                        </tr>
                    </table>
                    <!-- 检索  -->
                    <table id="table_report" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>渠道商名称</th>
                            <th>已录入设备数量（台）</th>
                            <th>激活设备数量（台）</th>
                            <th>转移时长权限</th>
                            <th>账号状态</th>
                            <th>最后登录时间</th>
                            <th>创建时间</th>
                            <th>最后修改时间</th>
                            <th class="center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <!-- 开始循环 -->
                        <c:choose>
                            <c:when test="${not empty channels}">
                                <c:forEach items="${channels}" var="channel">
                                    <tr>
                                        <td>
                                            <a href="javascript:;" style="text-decoration:none"
                                               onclick="edit('${channel.id }', 1);">${channel.name }</a>
                                        </td>
                                        <td>
                                            <a href="javascript:;" style="text-decoration:none"
                                               onclick="siMenu('z${menu.id}','lm${menu.pmenu.id}', '${menu.id}', '${menu.name}','${menu.url}?channelCode=${channel.channelCode}')">${channel.importNum }</a>
                                        </td>
                                        <td>${channel.activeNum }</td>
                                        <c:choose>
                                            <c:when test="${channel.shiftLimit == 1}">
                                                <td>是</td>
                                            </c:when>
                                            <c:otherwise>
                                                <td>否</td>
                                            </c:otherwise>
                                        </c:choose>
                                        <c:choose>
                                            <c:when test="${channel.status == 1}">
                                                <td style="color: blue">启用</td>
                                            </c:when>
                                            <c:otherwise>
                                                <td style="color: red">禁用</td>
                                            </c:otherwise>
                                        </c:choose>
                                        <td><fmt:formatDate value="${channel.lasttime }"
                                                            pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                        <td><fmt:formatDate value="${channel.createTime }"
                                                            pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                        <td><fmt:formatDate value="${channel.updateTime }"
                                                            pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                        <td style="width: 60px;">
                                            <div class='hidden-phone visible-desktop btn-group'>
                                                <c:if test="${fn:contains(butSet, 'edit')}">
                                                    <a class='btn btn-mini btn-info' title="编辑"
                                                       onclick="edit('${channel.id }', 0);">
                                                        <i class='icon-edit'></i>
                                                    </a>
                                                </c:if>
                                                <c:if test="${fn:contains(butSet, 'forbidden')}">
                                                    <c:choose>
                                                        <c:when test="${channel.status == 1}">
                                                            <a class='btn btn-mini btn-danger'
                                                               onclick="forbidden('${channel.id }', '${channel.status }', '${channel.name }');">
                                                                禁用
                                                            </a>
                                                        </c:when>
                                                        <c:otherwise>
                                                            <a class='btn btn-mini btn-info'
                                                               onclick="forbidden('${channel.id }', '${channel.status }', '${channel.name }');">
                                                                启用
                                                            </a>
                                                        </c:otherwise>
                                                    </c:choose>
                                                </c:if>
                                                <c:if test="${fn:contains(butSet, 'del')}">
                                                    <a class='btn btn-mini btn-danger' title="删除"
                                                       onclick="del('${channel.id }','${channel.name }');">
                                                        <i class='icon-trash'></i>
                                                    </a>
                                                </c:if>
                                                <a class='btn btn-mini btn-info'
                                                   onclick="resetPwd('${channel.id }', '${channel.name }');">
                                                    重置密码
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:when>
                            <c:otherwise>
                                <tr class="main_info">
                                    <td colspan="10" class="center">没有相关数据</td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                        </tbody>
                    </table>
                    <div class="page-header position-relative">
                        <table style="width:100%;">
                            <tr>
                                <td style="vertical-align:top;">
                                    <div class="pagination"
                                         style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </form>
            </div>
        </div><!--/row-->
    </div><!--/#page-content-->
</div><!--/.fluid-container#main-container-->
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
    <i class="icon-double-angle-up icon-only"></i>
</a>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>

<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->

<script type="text/javascript" src="static/js/myjs/head.js"></script>
<script type="text/javascript">
    $(top.hangge());

    //检索
    function search() {
        top.jzts();
        $("#userForm").submit();
    }

    //新增
    function add() {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "新增渠道";
        diag.URL = '<%=basePath%>channel/toAdd';
        diag.Width = 500;
        diag.Height = 650;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                if ('${page.currentPage}' == '0') {
                    top.jzts();
                    //setTimeout("self.location=self.location",100);
                    $("#userForm").submit();
                } else {
                    nextPage(${page.currentPage});
                }
            }
            diag.close();
        };
        diag.show();
    }

    //修改
    function edit(id, showType) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "编辑渠道";
        diag.URL = '<%=basePath%>channel/toEdit?id=' + id + "&showType=" + showType;
        diag.Width = 500;
        diag.Height = 650;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage(${page.currentPage});
            }
            diag.close();
        };
        diag.show();
    }

    //删除
    function del(id, name) {
        bootbox.confirm("是否删除[" + name + "]渠道?", function (result) {
            if (result) {
                top.jzts();
                var url = "<%=basePath%>channel/del";
                var postParam = {"id": id};
                $.post(url, postParam, function (data) {
                    if (data.code == 200) {
                        nextPage(${page.currentPage});
                    } else {
                        alert(data.msg)
                    }
                });
            }
        });
    }

    //启用、禁用
    function forbidden(id, status, name) {
        var msg = "";
        if (status == 1) {
            msg = "是否禁用[" + name + "]渠道？";
            status = 0;
        } else {
            msg = "是否启用[" + name + "]渠道？";
            status = 1;
        }
        bootbox.confirm(msg, function (result) {
            if (result) {
                top.jzts();
                var postParam = {"id": id, "status": status};
                var url = "<%=basePath%>channel/updateStatus";
                $.post(url, postParam, function (data) {
                    if (data.code == 200) {
                        nextPage(${page.currentPage});
                    }
                });
            }
        });
    }

    //重置密码
    function resetPwd(id, name) {
        bootbox.confirm("你确定要将渠道商[" + name + "]密码重置为123456吗?", function (result) {
            if (result) {
                top.jzts();
                var url = "<%=basePath%>channel/resetPwd"
                var postParam = {"id": id};
                $.post(url, postParam, function (data) {
                    if (data.code == 200) {
                        nextPage(${page.currentPage});
                    } else {
                        alert(data.msg)
                    }
                });
            }
        });
    }

</script>

<script type="text/javascript">
    $(function () {
        //下拉框
        $(".chzn-select").chosen({disable_search: true});
        $(".chzn-select-deselect").chosen({allow_single_deselect: true});
    });
</script>
</body>
</html>

